/**
 * Description
 *
 * Creation Date 26/12/2017
 * @author Candy
 */
import * as types from './../actionTypes';
import axios from 'axios';
axios.defaults.baseURL = 'http://47.100.6.170:3389';
axios.defaults.withCredentials = true;


//页面初次渲染时开始获取数据
const requestDataAction = path => {
	return {
		type: types.REQUEST_DATA,
		path
	}
};

//页面初次渲染时获取数据成功
const receiveDataAction = (path, data) => {
	return {
		type: types.RECEIVE_DATA,
		path,
		data
	}
};

//页面初次渲染时获取数据
export const initDataAction = (path, params) => {
	let url = path;
	return dispatch => {
		dispatch(requestDataAction(path));
		return axios({
			method: 'get',
			url,
			params
		})
			.then(res => dispatch(receiveDataAction(path, res.data)) )
			.catch(error => console.log(error))
	}
};
